package com.example.service;

import cn.hutool.core.date.DateUnit;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.StrUtil;
import com.example.entity.Account;
import com.example.entity.Notice;
import com.example.entity.Notice;
import com.example.entity.User;
import com.example.exception.CustomerException;
import com.example.mapper.NoticeMapper;
import com.example.utils.TokenUtils;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class NoticeService {

    @Autowired
    private NoticeMapper noticeMapper;

    public List<Notice> selectAll() {
        return noticeMapper.selectAll(null);
    }


    public PageInfo<Notice> selectPage(Integer pageNum, Integer pageSize, String name) {
        // 开启分页查询
        PageHelper.startPage(pageNum,pageSize);
        System.out.println("name======>"+name);
        List<Notice> list = noticeMapper.selectAll(name);
        return PageInfo.of(list);
    }
    public void add(Notice notice){
        notice.setTime(DateUtil.now());
        noticeMapper.insert(notice);
    }

    public void update(Notice notice) {
//        if(noticeMapper.selectByNoticename(notice.getNoticename())!=0){
//            throw new CustomerException("账号重复");
//        }
        noticeMapper.updateById(notice);
    }

    public void deleteById(Integer id) {
        noticeMapper.deleteById(id);
    }

//    public void deleteBatch(List<Notice> list) {
//        for (Notice notice : list) {
//            this.deleteById(notice.getId());
//        }
//    }

}